#ifndef __TOUCH_PAD_H__
#define __TOUCH_PAD_H__

#include "Graphic/Device.h"


#define MAX_SIMULTANEOUS_TOUCHES		(20)

enum TOUCH_TYPE
{
	TOUCH_NULL = 0,
	TOUCH_DOWN,
	TOUCH_UP,
	TOUCH_MOVE,
	TOUCH_CANCEL,
};

enum CURSOR_TYPE
{
	CT_NONE = 0,
	CT_LEFT,
	CT_MIDDLE,
	CT_RIGHT,
};

struct CTouchEvent
{
	int			x, y;
	void*		touchPointer;
	int			type;
	int			ctype;
	bool		bchecked;
	bool		benable;

	CTouchEvent(): x(0), y(0), touchPointer(NULL) , type(TOUCH_NULL), ctype(CT_LEFT), bchecked(false), benable(false) {}

	CTouchEvent(int _x, int _y, void* _touchPointer, int _type, int _ctype = CT_LEFT, bool _bchecked = false, bool _benable = false) : x(_x), y(_y), touchPointer(_touchPointer) ,type(_type), ctype(_ctype), bchecked(_bchecked), benable(_benable){}

	CTouchEvent(const CTouchEvent& touchEvent) : x(touchEvent.x), y(touchEvent.y), touchPointer(touchEvent.touchPointer), type(touchEvent.type), ctype(touchEvent.ctype), bchecked(touchEvent.bchecked), benable(touchEvent.benable){}
	CTouchEvent& operator = (const CTouchEvent& touchEvent)
	{
		if(this != &touchEvent)
		{
			x = touchEvent.x;
			y = touchEvent.y;
			touchPointer = touchEvent.touchPointer;
			type = touchEvent.type;
			ctype = touchEvent.ctype;
			bchecked = touchEvent.bchecked;
			benable = touchEvent.benable;
		}
		return *this;
	}

	inline bool operator == (const CTouchEvent &touchEvent) 
	{
		return (x == touchEvent.x) && (y = touchEvent.y) && (touchPointer == touchEvent.touchPointer);
	}

};

class CTouchPad
{
public:

public:

	CTouchPad();
	~CTouchPad();

	int m_nTouchEventCount;
	CTouchEvent	m_TouchEvents[MAX_SIMULTANEOUS_TOUCHES];


	void PadTouchEvent(int x, int y, void* touchPointer, int cType = CT_LEFT);
	void PadUntouchEvent(int x, int y, void* touchPointer, int cType = CT_LEFT);
	void PadMoveEvent(int x, int y, void* touchPointer);
	void PadCancelEvent(int x, int y, void* touchPointer);

	void Update();
	void Clear();

	//click
	CTouchEvent* CheckClicked();
	CTouchEvent* CheckClickedInRegion(rect<int> * el);

	//move
	CTouchEvent* CheckMoved(void* touchPointer = NULL);
	CTouchEvent* CheckMovedInRegion(rect<int> * el, void* touchPointer = NULL);

	//unclick
	CTouchEvent* CheckUnClicked(void* touchPointer = NULL);
	CTouchEvent* CheckUnClickedInRegion(rect<int> * el,void* touchPointer = NULL);

	CTouchEvent* CheckUnMovedInRegion(rect<int> * el);

	
	
	

	static int m_nLastX,m_nLastY;
};

#endif// __TOUCH_PAD_H__